﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SiteRequireLogin.Master" AutoEventWireup="true" CodeBehind="CategoryMgmt.aspx.cs" Inherits="TranTekBE.CategoryMgmt" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="BodyContent" runat="server">
    <asp:UpdatePanel ID="UpdatePanel" runat="server">
    <ContentTemplate>
        <h1>Categories</h1>
        <input type="hidden" runat="server" id="hdList" />
        <table style="width:100%">
            <tr>
                <td class="tdLeftM msgError"><asp:Literal ID="ltError" runat="server" /></td>
            </tr>
            <tr>
                <td class="tdLeftM">
                    <asp:Button ID="btnDelete" runat="server" Text="Delete" Width="70px" CommandName="Delete" OnClientClick="return DeleteConfirm()" oncommand="ControlClick_Command" /> <%--onclick="btnDelete_Click"--%>
                    <button id="btnAdd" style="width:70px;" type="button">Add</button>
                    <button id="btnPriority" style="width:115px;" type="button">Display Priority</button>
                    <asp:Button ID="btnSort" runat="server" Text="Sort By" Width="70px" CommandName="Sort" oncommand="ControlClick_Command" />
                    <asp:DropDownList ID="ddlSortBy" runat="server">
                        <asp:ListItem Text="Category Name" Value="catName" />
                        <asp:ListItem Text="Active" Value="catStatus" />
                        <asp:ListItem Text="Priority" Value="catShowSeq" Selected="True" />
                    </asp:DropDownList>
                    <asp:DropDownList ID="ddlSortDirect" runat="server">
                        <asp:ListItem Text="Ascending" Value="ASC" Selected="True" />
                        <asp:ListItem Text="Descending" Value="DESC" />
                    </asp:DropDownList>
                    <asp:PlaceHolder ID="phPageNavigation" runat="server">
                        <asp:Button ID="btnGoPage" runat="server" Text="Go to" CommandName="GoToPage" oncommand="ControlClick_Command" />
                        <asp:TextBox ID="txtGoPage" runat="server" Width="30px" MaxLength="3" />
                        <asp:Button ID="btnPrev" runat="server" CommandName="GoToPrev" Text="<<" oncommand="ControlClick_Command" />
                        <asp:Literal ID="ltPage" runat="server" />
                        <asp:Button ID="btnNext" runat="server" CommandName="GoToNext" Text=">>" oncommand="ControlClick_Command" />
                    </asp:PlaceHolder>
                    Records/Page: <asp:DropDownList ID="ddlPageSize" runat="server" AutoPostBack="true" onselectedindexchanged="ddlPageSize_SelectedIndexChanged" />
                </td>
            </tr>
            <tr>
                <td class="tdLeftT">
                    <table style="width:100%" class="tblGrid">
                        <tr>
                            <th class="thGrid" style="width:5%;">No. <input type="checkbox" id="chkAll" /></th>
                            <th class="thGrid" style="width:30%;"><asp:LinkButton ID="lbNameSort" runat="server" Text="Category" CommandArgument="DESC" CommandName="catName" onclick="Sort_Click" CssClass="GridHeader" /></th>
                            <th class="thGrid" style="width:5%;"><asp:LinkButton ID="lbStatusSort" runat="server" Text="Active" CommandArgument="DESC" CommandName="catStatus" onclick="Sort_Click" CssClass="GridHeader" /></th>
                            <th class="thGrid" style="width:15%;"><asp:LinkButton ID="lbPrioritySort" runat="server" Text="Display Priority" CommandArgument="ASC" CommandName="catShowSeq" CssClass="GridHeader sortAsc" onclick="Sort_Click" /></th>
                            <th class="thGrid" style="width:45%;">Comments</th>
                        </tr>
                        <tr>
                            <td class="tdGrid tdCenterM">
                                <table class="centerObject">
                                    <tr>
                                        <td><asp:ImageButton ID="btnClearSearch" runat="server" ImageUrl="images/ico_clear_search.gif" 
                                    ToolTip="Clear Search" onclick="btnClearSearch_Click" /></td>
                                        <td><asp:ImageButton ID="btnSearch" runat="server" ImageUrl="images/ico_search.gif" ToolTip="Search" 
                                    onclick="btnSearch_Click" /></td>
                                    </tr>
                                </table>
                            </td>
                            <td class="tdGrid tdCenterM"><asp:TextBox ID="txtCategoryName" runat="server" Width="98%" /></td>
                            <td class="tdGrid tdCenterM">
                                <asp:DropDownList ID="ddlStatus" runat="server">
                                    <asp:ListItem Text="All" Value="" />
                                    <asp:ListItem Text="Yes" Value="1" />
                                    <asp:ListItem Text="No" Value="0" />
                                </asp:DropDownList>
                            </td>
                            <td>&nbsp;</td>
                            <td class="tdGrid tdCenterM"><asp:TextBox ID="txtCategoryDesc" runat="server" Width="98%" /></td>
                        </tr>
                        <asp:Repeater ID="rpCategory" runat="server">
                            <ItemTemplate>
                                <tr>
                                    <td class="tdGrid tdLeftM"><%# Container.ItemIndex + 1 %> <input type="checkbox" id="chk_<%#Eval("CategoryISN")%>" value="<%#Eval("CategoryISN")%>" /></td>
                                    <td class="tdGrid tdLeftM">
                                        <a href="#" id="edit_<%#Eval("CategoryISN")%>"><%# ThuVien.FunctionsUtils.HTMLEncode(Eval("catName"))%></a>
                                    </td>
                                    <td class="tdGrid tdCenterM"><%#ThuVien.FunctionsUtils.GetStatus(Eval("catStatus"))%></td>
                                    <td class="tdGrid tdRightM"><%#Eval("catShowSeq") %></td>
                                    <td class="tdGrid tdLeftM"><%# ThuVien.FunctionsUtils.HTMLEncode(Eval("catDesc")) %></td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                        <asp:Literal ID="ltNoRecord" runat="server" Visible="false">
                            <tr><td colspan="5" class="tdGrid tdCenterM">No Record</td></tr>
                        </asp:Literal>                        
                    </table>
                </td>
            </tr>
        </table>
        <script type="text/javascript">
            function LoadJS() {
                requiredCheckBox("btnDelete", "chk_");
                //check all
                $("#chkAll").on("click", function() {
                    var checked_status = this.checked;
                    $('input[id^="chk_"]').each(function() {
                        this.checked = checked_status;
                        //$(this).parents('tr:first').removeClass('selected');
                        //if (this.checked)
                        //    $(this).parents('tr:first').addClass('selected');

                        requiredCheckBox("btnDelete", "chk_");
                    });
                });
                //check box
                $('input[id^="chk_"]').on("click", function() {
                    console.log(this.checked);
                    checkOrUncheckForCheckAll();
                    requiredCheckBox("btnDelete", "chk_");
                });
                //add
                $("#btnAdd").on("click", function(e) {
                    e.preventDefault();
                    OpenDialog("Add Category", "Category.aspx", 300, 500);
                });
                //edit cat
                $('a[id^="edit_"]').on("click", function(e) {
                    e.preventDefault();                
                    var id = $(this).attr("id").replace("edit_", "");
                    OpenDialog("Edit Category", "Category.aspx?isn=" + id, 300, 500);
                });
                //priority
                $('button[id="btnPriority"]').on("click", function(e) {
                    e.preventDefault();
                    OpenDialog("Category Priority", "CategoryPriority.aspx", 500, 400);
                });
                //$("ul[id^='mnu']").menu();
            }
            function requiredCheckBox(btnID, chkID) {
                $('input[id$="' + btnID + '"]').attr('disabled', true);
                var lstISN = [];

                //for each tat ca checkbox checked
                $('input[id^="' + chkID + '"]:checked').each(function() {
                    $('input[id$="' + btnID + '"]').attr('disabled', false);
                    var isn = this.id.replace(chkID, "");
                    lstISN.push(isn);
                });

                // set value va`o hidden field
                $('input[id$="hdList"]').val(lstISN.join(","));
            }
            function checkOrUncheckForCheckAll() {
                var checked = false;
                if ($('input[id^="chk_"]:checkbox').length == $('input:checkbox[id^="chk_"]:checked').length) {
                    checked = true;
                }
                $('#chkAll').prop("checked", checked);
            }
            function DeleteConfirm(){
                if ($('input:checkbox[id^="chk_"]:checked').length > 0) {
                    return confirm("Are you sure to delete?");
                }
                else {
                    return false;
                }
            }
        </script>
    </ContentTemplate>
</asp:UpdatePanel>
</asp:Content>